package com.sevntu.apvs.modeling;

import java.io.PrintWriter;
import java.util.List;

import com.sevntu.apvs.duelement.Element;
import com.sevntu.apvs.dModel.DModel;

public class Element_Model {
	public static void File_To_Diagr(DModel Mass, String file) {
		PrintWriter out1 = null;
		int circuit[][] = new int[Mass.getCircuitList().size()][5];
		for (int i = 0; i < Mass.getCircuitList().size(); i++) {
			circuit[i][0] = Mass.getCircuitList().get(i).getCircuitId();
			circuit[i][1] = Mass.getCircuitList().get(i).getElemNumOut();
			circuit[i][2] = Mass.getCircuitList().get(i).getElemContactOut();
			circuit[i][3] = Mass.getCircuitList().get(i).getElemNumIn();
			circuit[i][4] = Mass.getCircuitList().get(i).getElemContactIn();
		}
		try {
			out1 = new PrintWriter(file);
			for (int i = 0; i < circuit.length; i++) {
				out1.print(circuit[i][0] + " ");
				for (int j = 0; j < Mass.getElemList().size(); j++) {
					if (circuit[i][1] == Mass.getElemList().get(j).id) {
						out1.print(Mass.getElemList().get(j).name + " ");
					}
					if (circuit[i][1] == 0) {
						out1.print("In ");
						break;
					}
				}
				out1.print(circuit[i][1] + " ");
				out1.print(circuit[i][2] + " ");
				for (int j = 0; j < Mass.getElemList().size(); j++) {
					if (circuit[i][3] == Mass.getElemList().get(j).id) {
						out1.print(Mass.getElemList().get(j).name + " ");
					}
					if (circuit[i][3] == 0) {
						out1.print("Out ");
						break;
					}
				}
				out1.print(circuit[i][3] + " ");
				out1.print(circuit[i][4]);
				out1.println();
			}
			out1.close();
		} catch (Exception e) {
			System.out.print(e);
		} finally {
		}
	}

}
